#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include <QFontDialog>
#include <QSettings>
#include <QFont>

SettingsDialog::SettingsDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SettingsDialog)
{
    ui->setupUi(this);

    QSettings settings;
    QFont font;
    font.setFamily(settings.value("editor_font_family", "").toString());
    font.setPointSize(settings.value("editor_font_size", 14).toInt());
    font.setBold(settings.value("editor_font_bold", false).toBool());
    font.setItalic(settings.value("editor_font_italic", false).toBool());
    ui->label_font->setFont(font);
}

SettingsDialog::~SettingsDialog()
{
    delete ui;
}

QFont* SettingsDialog::GetFont()
{
    QFont* retfont = new QFont(ui->label_font->font());
    return retfont;
}

void SettingsDialog::on_pushButton_clicked()
{
    QFontDialog fontdialog(ui->label_font->font());
    if (fontdialog.exec())
    {
        ui->label_font->setFont(fontdialog.currentFont());
    }
}

void SettingsDialog::on_buttonBox_accepted()
{
    QSettings settings;
    settings.setValue("editor_font_family", ui->label_font->font().family());
    settings.setValue("editor_font_size", ui->label_font->font().pointSize());
    settings.setValue("editor_font_bold", ui->label_font->font().bold());
    settings.setValue("editor_font_italic", ui->label_font->font().italic());
}
